const db = wx.cloud.database()
Page({
  data: {
    ckjfmx: false, //显示积分明细
    user: {},
    xinxi: {},
    score: 0, //积分
    balance: 0, //兑换券
    autoplay: true, //是否自动切换
    interval: 3000, //自动切换时间间隔,3s
    duration: 1000, //  滑动动画时长1s
    swiperCurrent: '',
    imgList: [{
        img: 'cloud://womenlia-2gcdym6fb861b775.776f-womenlia-2gcdym6fb861b775-1331674006/tpp/Screenshot_20250101_161058.jpg',
      },
      {
        img: 'cloud://womenlia-2gcdym6fb861b775.776f-womenlia-2gcdym6fb861b775-1331674006/tpp/mmexport1728303258867.jpg',
      },
      {
        img: 'cloud://womenlia-2gcdym6fb861b775.776f-womenlia-2gcdym6fb861b775-1331674006/tpp/IMG_20241127_163733.jpg',
      },
      {
        img: 'cloud://womenlia-2gcdym6fb861b775.776f-womenlia-2gcdym6fb861b775-1331674006/tpp/IMG_20241030_204933.jpg'
      },
    ]
  },
  swiperChange: function (e) {
    this.setData({
      swiperCurrent: e.detail.current
    })
  },
  /*
   * 图片预览
   * @param e
   */
  previewImage(e) {
    let currentUrl = e.currentTarget.dataset.src;
    let urls = this.data.imgList.map(i => i.img)
    wx.previewImage({
      current: currentUrl, // 当前显示图片的http链接
      urls: urls // 需要预览的图片http链接列表
    })
  },
  // 页面隐藏显示
  onHide() {
    this.setData({
      autoplay: false
    })
  },
  onShow() {
    this.setData({
      autoplay: true
    })
  },
  //页面离开执行
  onUnload: function () {
    // 在页面卸载时清除定时器
    console.log("离开");
  },

  onLoad() {
    try {
      var value = wx.getStorageSync('autt')
      if (value) {
        // Do something with return value
        console.log(value);
        this.setData({
          user: value
        })
      }
    } catch (e) {
      // Do something when catch error
    }
    this.getDtaeBususer()
  },
  // 获取数据库积分信息
  getDtaeBususer() {
    db.collection('users').doc(this.data.user.id).get({
      success: res => {
        // res.data 包含该记录的数据
        console.log(res.data)
        this.setData({
          xinxi: res.data
        })
      }
    })
  },
  //查看积分明细
  jifenmingxi(e) {
    this.setData({
      ckjfmx: true
    })
  },
  //关闭积分明细
  clue() {
    this.setData({
      ckjfmx: false
    })
  }
})